package com.dq.health.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dq.health.dao.role.SysRoleMapper;
import com.dq.health.dao.role.SysRoleMenuMapper;
import com.dq.health.dto.request.role.QueryRoleListRequest;
import com.dq.health.entity.role.SysRole;
import com.dq.health.entity.role.SysRoleMenu;
import com.dq.health.service.IAPIRoleService;

/**
 * <>
 *
 * @Author: chenxin
 * @Date: 2021/5/17
 */
@Service
public class RoleServiceImpl implements IAPIRoleService {

    @Resource
    SysRoleMapper sysRoleMapper;

    @Resource
    SysRoleMenuMapper sysRoleMenuMapper;

    @Override
    public List<SysRole> getAllEnableRole() {
        return sysRoleMapper.selectList(new QueryWrapper<SysRole>().lambda().eq(SysRole::getStatus, 1));
    }

    @Override
    public IPage<SysRole> getRoleList(QueryRoleListRequest req) {
        return null;
    }

    @Override
    public SysRole getSysRole(Long roleId) {
        return sysRoleMapper.selectById(roleId);
    }

    @Override
    public void saveRole(SysRole sysRole, List<Long> menuIds) {
        sysRoleMapper.insert(sysRole);
        for (Long menuId : menuIds){
            SysRoleMenu sysRoleMenu = new SysRoleMenu();
            sysRoleMenu.setRoleId(sysRole.getRoleId());
            sysRoleMenu.setMenuId(menuId);
            sysRoleMenu.setCreateTime(new Date());
            sysRoleMenuMapper.insert(sysRoleMenu);
        }
    }

    @Override
    public void updateRoleBaseInfo(SysRole sysRole) {
        sysRoleMapper.updateById(sysRole);
    }

    @Override
    public void updateRole(SysRole sysRole, List<Long> menuIds) {

    }
}
